<template>
    <div>
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" :label-position="labelPosition" label-width="150px" class="demo-ruleForm">

        <div>
            <div v-if="showForm" class="container" style="margin-top:20px">
                <h3 style="margin-bottom: 20px">新建物料</h3>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="物料类型：">
                            {{ruleForm.materialType}}
                        </el-form-item>
						<el-form-item label="产品大类：" v-if="keliShow">
							{{ruleForm.inventoryType}}
						</el-form-item>
                        <el-form-item label="产品大类：" v-if="ruleForm.materialType == '中药饮片'">
                            {{ruleForm.inventoryType}}
                        </el-form-item>
                        <el-form-item label="物料代码：">
                            {{ruleForm.materialCode ||'无'}}
                        </el-form-item>
                        <div v-if='switchHeadTab == "生产系统"'>
                            <el-form-item label="* 标准类型：" prop="ypCodeStandard" v-show='zypy' v-if="this.ruleForm.materialType !='中药材' && this.ruleForm.materialType != '辅料'">
                                {{ypCodeStandard}}
                            </el-form-item>
                        </div>
                        <div v-if="keliShow || zypy">

                            <el-form-item label="发药机编码：" v-if='switchHeadTab=="生产系统"'>
                                {{ruleForm.dispenserCode}}
                            </el-form-item>
                            <el-form-item label="装量：" prop="spec">
                                {{ruleForm.pelletWeight}}

                            </el-form-item>
                            <el-form-item label="上市备案号：" v-if='switchHeadTab=="生产系统"'>
                                {{ruleForm.prodRecordCode}}
                            </el-form-item>
                        </div>
                        <div v-if="ruleForm.materialType != '配方颗粒(浸膏粉)' && ruleForm.materialType != '配方颗粒'">
                            <el-form-item v-for="(item,index) in technologies"  :key="index" :label="'产地'+(index+1)+'：'">
                             {{item.specification}}
                                <!-- <el-input v-model="item.specification" prop="specification" style="width:200px" placeholder="产地"></el-input>
                                <el-button @click = "deleteUnit(index)" class="delete_btn" style="margin-left:20px;">删除</el-button> -->
                            </el-form-item>
                        </div>
                        <el-col>
                            <div v-if="ruleForm.materialType == '中药饮片'">
                                <el-form-item  label='注意事项:'>
                                    {{ruleForm.remark}}
                                </el-form-item>
                                <el-form-item  label='用法与用量:'>
                                  {{ruleForm.usage}}
                                </el-form-item>
<!--                                <el-form-item  label='用量:'>-->
<!--                                    {{ruleForm.dose}}-->
<!--                                </el-form-item>-->
                            </div>
                        </el-col>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="名称：">
                            {{ruleForm.breedName}}
                        </el-form-item>
                        <div v-if="keliShow || zypy">
                            <el-form-item label="存货代码：">
                                {{ruleForm.inventoryCode}}
                            </el-form-item>
                            <el-form-item label="规格：">
                                {{zypy?'细粉':ruleForm.loadingQuantity}}{{zypy?'':ruleForm.loadingUnits}}
                            </el-form-item>
                        </div>
						<el-form-item label="保质期：">
						    {{ruleForm.deadLine}}月
						</el-form-item>
                        <div v-if="keliShow">
                            <el-form-item label="规格对应饮片：" class="styleWidth">
                                 {{ruleForm.ypQuantity}}{{ruleForm.ypUnits}}
                            </el-form-item>
                            <el-form-item label="储存条件：">
                                {{ruleForm.storage}}
                            </el-form-item>
                        </div>
                        <el-form-item label="储存条件：" v-if="ruleForm.materialType == '中药饮片'">
                            {{ruleForm.storage}}
                        </el-form-item>
                        <div v-if="ssssshow">

<!--                            <el-form-item label="规格码：">-->
<!--                                &lt;!&ndash; <el-input placeholder="请输入内容" v-model.trim="ruleForm.specsCode" style="width: auto"></el-input> &ndash;&gt;-->
<!--                             {{ruleForm.specsCode}}-->
<!--                            </el-form-item>-->


                        </div>
                        <div v-if="zypy">
                            <el-form-item label="功能与主治：">
                                {{ruleForm.effect}}
                            </el-form-item>
                        </div>
                    </el-col>

                  <el-col>
                      <el-form-item label="中药饮片执行标准：" v-if="ruleForm.materialType == '中药饮片'">
                          {{this.ruleForm.checkName}}
                      </el-form-item>
                      <el-form-item label="提取饮片执行标准：" v-if="ruleForm.materialType == '中药饮片(半成品)'">
                          {{this.ruleForm.checkName}}
                      </el-form-item>
                    <el-form-item label="提取饮片执行标准：" v-if="ruleForm.materialType == '提取饮片'">
                      {{this.ruleForm.checkName}}
                    </el-form-item>
                    <el-form-item label="中药配方颗粒执行标准：" v-if="ruleForm.materialType == '配方颗粒'">
                      {{this.ruleForm.checkName}}
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-form-item class="footerFixed">
                    <el-button type="primary" @click="submitForm">确认无误</el-button>
                    <el-button @click="showForm = false">返回修改</el-button>
                </el-form-item>
            </div>
            <div v-else class="container" style="margin-top:20px">
                <h3 style="margin-bottom: 20px">新建物料</h3>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="物料类型：" prop="materialType">
                            <el-select v-model="ruleForm.materialType" @change="changeMtype" filterable placeholder="请选择" style="width: 200px;">
                                <el-option v-if='switchHeadTab == "生产系统"' label="中药材" value="中药材"></el-option>
                                <el-option v-if='switchHeadTab == "生产系统"' label="辅料" value="辅料"></el-option>
                                <el-option v-if='switchHeadTab == "中药饮片"' label="中药饮片" value="中药饮片"></el-option>
                                <el-option v-if='switchHeadTab == "中药饮片"' label="中药饮片(半成品)" value="中药饮片(半成品)"></el-option>
                                <el-option v-if='switchHeadTab == "生产系统"' label="提取饮片" value="提取饮片"></el-option>
								<el-option v-if='switchHeadTab == "生产系统"' label="配方颗粒(浸膏粉)" value="配方颗粒(浸膏粉)"></el-option>
                                <el-option v-if='switchHeadTab == "生产系统"' label="配方颗粒" value="配方颗粒"></el-option>
                            </el-select>
                        </el-form-item>
						<el-form-item v-if="keliShow" label="产品大类：" prop="inventoryType">
						    <el-select v-model="ruleForm.inventoryType"  filterable placeholder="请选择" style="width: 200px;">
						        <el-option label="C50天津中药配方颗粒" value="C50天津中药配方颗粒"></el-option>
						        <el-option label="C50中药配方颗粒" value="C50中药配方颗粒"></el-option>
						        <el-option label="C20连袋中药配方颗粒" value="C20连袋中药配方颗粒"></el-option>
                                <el-option label="C20中药配方颗粒" value="C20中药配方颗粒"></el-option>
                                <el-option label="C51中药配方颗粒" value="C51中药配方颗粒"></el-option>
                                <el-option label="C60中药配方颗粒" value="C60中药配方颗粒"></el-option>
                                <el-option label="C70中药配方颗粒" value="C70中药配方颗粒"></el-option>
                                <el-option label="C80中药配方颗粒" value="C80中药配方颗粒"></el-option>
                                <el-option label="C90中药配方颗粒" value="C90中药配方颗粒"></el-option>
						    </el-select>
						</el-form-item>
                        <el-form-item v-if="ruleForm.materialType=='中药饮片'" label="产品大类：" prop="inventoryType">
                            <el-select v-model="ruleForm.inventoryType"  filterable placeholder="请选择" style="width: 200px;">
                                <el-option label="C10中药饮片" value="C10中药饮片"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item  label="物料代码：" prop="materialCode" v-if="ruleForm.materialType != '配方颗粒' || ruleForm.materialType == '中药饮片(半成品)'">
                            <el-input placeholder="请输入" v-model.trim="ruleForm.materialCode" style="width: auto"></el-input>
                        </el-form-item>
                        <!-- <el-form-item label="产地：">
                            <el-input placeholder="请输入内容" v-model="ruleForm.place" style="width: auto"></el-input>
                        </el-form-item> -->
                        <el-form-item label="* 标准类型：" prop="standard" v-show='!zypy' v-if="(this.ruleForm.materialType !='中药材' && this.ruleForm.materialType != '辅料' && ruleForm.materialType != '中药饮片(半成品)')">
                            <el-select v-model="ruleForm.ypCodeStandard"  @change="getchecklist"  filterable placeholder="请选择" style="width:auto;">
                                <el-option label="国标" value="1"></el-option>
                                <el-option label='省标' value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <div v-if="keliShow || zypy">

                           <!-- <el-form-item label="物料代码：">
                                <el-input placeholder="请输入" v-model="ruleForm.materialCode" style="width: auto"></el-input>
                            </el-form-item> -->
                            <el-form-item label="发药机编码：" v-if='switchHeadTab == "生产系统"'>
                                <el-input placeholder="请输入内容" v-model.trim="ruleForm.dispenserCode" style="width: auto"></el-input>
                            </el-form-item>
                            <!-- <el-form-item label="装量对应饮片：" class="styleWidth">
                                <el-input placeholder="请输入" v-model.trim="ruleForm.ypQuantity" style="width: auto">
                                    <template slot="append">
                                        <el-select v-model="ruleForm.ypUnits" :disabled="isDisabled" placeholder="单位" style="width:80px">

                                            <el-option label="g" value="g"></el-option>
                                        </el-select>
                                    </template>
                                </el-input>
                            </el-form-item> -->
                            <el-form-item label="规格：" prop="spec" v-if='switchHeadTab == "生产系统"'>
                                 <el-input placeholder="请输入" v-model.trim="ruleForm.loadingQuantity" style="width: auto">
                                    <template slot="append" style="width: 150px">
                                        <el-select v-model="ruleForm.ypUnits" :disabled="isDisabled" placeholder="单位" style="width:80px">
                                            <el-option label="g" value="g"></el-option>
                                        </el-select>
                                    </template>
                                </el-input>

                                <!-- <el-input placeholder="请输入" v-model="ruleForm.pelletWeight" style="width: auto">
                                    <template slot="append" style="width: 150px">
                                        <el-select v-model="ruleForm.loadingUnits" :disabled="isDisabled" placeholder="单位" style="width:80px">

                                            <el-option label="g" value="g"></el-option>
                                        </el-select>
                                    </template>
                                </el-input> -->

                            </el-form-item>
                            <el-form-item label="规格：" prop="spec" v-else>
                                <el-select v-model="ruleForm.ypUnits" placeholder="单位" style="width: 200px">
                                    <el-option  label="细粉" value="细粉"></el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item v-if='!zypy' label="规格对应饮片：" class="styleWidth">
                                <el-input placeholder="请输入" v-model.trim="ruleForm.ypQuantity" style="width: auto">
                                    <template slot="append">
                                        <el-select v-model="ruleForm.ypUnits" :disabled="isDisabled" placeholder="单位" style="width:80px">

                                            <el-option label="g" value="g"></el-option>
                                        </el-select>
                                    </template>
                                </el-input>
                                <!-- <el-input placeholder="请输入" v-model.trim="ruleForm.yinpianWeight" style="width: auto">
                                    <template slot="append">
                                        <el-select v-model="ruleForm.ypUnits" :disabled="isDisabled" placeholder="单位" style="width:80px">

                                            <el-option label="g" value="g"></el-option>
                                        </el-select>
                                    </template>
                                </el-input> -->
                            </el-form-item>
                            <el-form-item label="上市备案号：" v-if='switchHeadTab =="生产系统"'>
                                <el-input placeholder="请输入内容" v-model.trim="ruleForm.prodRecordCode" style="width: auto"></el-input>
                            </el-form-item>
                            <!-- 配方颗粒(浸膏粉) -->
                        </div>
                        <div v-if="(ruleForm.materialType != '配方颗粒(浸膏粉)' && ruleForm.materialType != '配方颗粒') || ruleForm.materialType == '中药饮片(半成品)'">
                            <el-form-item v-for="(item,index) in technologies"  :key="index" :label="'产地'+(index+1)+'：'" >
                                <el-input v-model="item.specification" prop="specification" style="width:200px" placeholder="产地"></el-input>
                                <el-button @click = "deleteUnit(index)" class="delete_btn" style="margin-left:20px;">删除</el-button>
                            </el-form-item>
                            <el-form-item>
                                <el-button @click="added_unit" class='added_unit'>添加一条</el-button>
                            </el-form-item>
                        </div>

                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="名称：" prop="breedName">
                            <el-input placeholder="请输入内容" v-model.trim="ruleForm.breedName" @change="getchecklist" style="width: auto">
                                <!-- <template slot="append">
                                    <el-select v-model="ruleForm.specUnits" placeholder="单位" style="width:80px">
                                        <el-option v-for="(item,index) in units" :key="index" :label="item.name" :value="item.name"></el-option>
                                    </el-select>
                                </template> -->
                            </el-input>
                            <!-- <el-button style="margin-left:10px" @click="unitLink">单位管理</el-button> -->
                        </el-form-item>

                        <div v-if="keliShow||zypy">
                            <el-form-item label="存货代码：" prop="inventoryCode">
                                <el-input placeholder="请输入内容" v-model.trim="ruleForm.inventoryCode" style="width: auto"></el-input>
                            </el-form-item>
                            <el-form-item label="装量：" class="styleWidth">
                                <el-input placeholder="请输入" v-model="ruleForm.pelletWeight" style="width: auto">
                                    <template slot="append" style="width: 150px">
                                        <el-select v-model="ruleForm.loadingUnits" :disabled="isDisabled" placeholder="单位" style="width:80px">

                                            <el-option label="g" value="g"></el-option>
                                        </el-select>
                                    </template>
                                </el-input>

                            </el-form-item>
                        </div>
                        <el-form-item label="保质期：">
                            <el-input placeholder="请输入内容" v-model.trim="ruleForm.deadLine" style="width: auto"></el-input>
                          <span style="margin-left:20px;">月</span>
                        </el-form-item>

                        <div v-if="keliShow||zypy">

                            <el-form-item label="储存条件：">
                                <el-input placeholder="请输入内容" v-model.trim="ruleForm.storage" style="width: auto"></el-input>

                            </el-form-item>
                        </div>
<!--                        <div v-if="ssssshow">-->
<!--                            <el-form-item label="规格码：">-->
<!--                                <el-input placeholder="请输入内容" v-model.trim="ruleForm.specsCode" style="width: auto"></el-input>-->
<!--                            </el-form-item>-->
<!--                        </div>-->
                        <div v-if="zypy">
                            <el-form-item label="功能与主治：">
                                <el-input type="textarea" :rows="3" placeholder="请输入内容" v-model.trim="ruleForm.effect" style="width:350px"></el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                    <el-col>
                        <div v-if="ruleForm.materialType == '中药饮片'">
                            <el-form-item  label='注意事项:'>
                                <el-input placeholder="请输入内容" v-model.trim="ruleForm.remark" style="width: auto"></el-input>
                            </el-form-item>
                            <el-form-item  label='用法与用量:'>
                                <el-input placeholder="请输入内容" v-model.trim="ruleForm.usage" style="width: auto"></el-input>
                            </el-form-item>
<!--                            <el-form-item  label='用量:'>-->
<!--                                <el-input placeholder="请输入内容" v-model.trim="ruleForm.dose" style="width: auto"></el-input>-->
<!--                            </el-form-item>-->
                        </div>
                      <el-form-item v-if="switchHeadTab == '中药饮片'" label='中药饮片执行标准：'>
                          <el-select v-model="piecesStandardName" placeholder="请选择" style="width: auto;">
                              <el-option
                                  v-for="item in piecesStandardList"
                                  :key="item"
                                  :label="item"
                                  :value="item"
                              >
                                  {{item}}
                              </el-option>
                          </el-select>
                      </el-form-item>
                      <el-form-item label="提取饮片执行标准：" v-if="ruleForm.materialType == '提取饮片'">
                        <el-select v-model="standard" multiple collapse-tags @change="changeStandard" value-key="id" filterable placeholder="请选择" style="width: auto;">
                          <el-option
                              v-for="item in checkList"
                              :key="item.id"
                              :label="item.checkName"
                              :value="item"
                          >
                            {{item.checkName}}
                          </el-option>
                        </el-select>
                      </el-form-item>
                      <el-form-item label="中药配方颗粒执行标准：" v-if="ruleForm.materialType == '配方颗粒'">
                        <el-select v-model="standard" multiple collapse-tags @change="changeStandard" value-key="id" filterable placeholder="请选择" style="width: auto;">
                          <el-option
                              v-for="item in checkList"
                              :key="item.id"
                              :label="item.checkName"
                              :value="item"
                          >
                            {{item.checkName}}
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                </el-row>
                <el-form-item class="footerFixed">
                    <el-button type="primary" @click="submitRules('ruleForm')">提交</el-button>
                    <el-button @click="backPage">返回</el-button>
                </el-form-item>
            </div>
        </div>
        </el-form>
    </div>
</template>

<script>
import {materialBreed_save,materialBreed_findById,materialBreed_update,unit_findByList,materialBreed_isExist,materialBreed_findInventoryCodeIsExist} from "@/request/api";
import uploadImg from '../../../common/uploadImg';
import {check_findByName} from '../../../../request/api';
import { mapState } from 'vuex';
    export default {
        components: {
            uploadImg
        },
        data() {
            return {
                piecesStandardName:'',
                piecesStandardList:[],
                zypy:false,
                tableData:[],
              checkList:[],
              standard:[],
                ypCodeStandard:'',
                technologies:[
                    {
                        specification:''
                    }
                ],
                ssssshow:false,
                labelPosition:'right',
                showForm: false,
                keliShow: false,
                isDisabled: true,
                wlShow: false,
                ruleForm: {
                    remark:'',
                    usage:'',
                    dose:'',
					deadLine:'',
                    breedName:'',
                    effect:'',
                    place: '',
                    materialType: '',
                    loadingQuantity: '',
                    loadingUnits: 'g',
                    // spec: '',
                    dispenserCode: '',
                    inventoryCode: '',
                    ypQuantity: '',
                    ypUnits:'g',
                    materialCode: '',
                  ypCodeStandard:''
                },
                rules: {
                    breedName: [
                        { required: true, message: '不能为空', trigger: 'blur' }
                    ],
                    materialType: [
                        { required: true, message: '不能为空', trigger: 'change' },
                    ],
                    inventoryType: [
                        { required: true, message: '不能为空', trigger: 'blur' }
                    ],
                    inventoryCode: [
                        { required: true, message: '不能为空', trigger: 'blur' }
                    ],
                },
                units:[

                ],
                materialTypeStor: ''
            };
        },
        computed:{
            ...mapState(['switchHeadTab'])
        },
        mounted(){


            console.log(this.ypUnits);

            this.id = this.$route.query.id
            if(this.$route.query.type == '中药饮片'){
                this.zypy = true
                this.keliShow = false
                this.wlShow = false
                this.materialCode = ""
                this.ruleForm.ypUnits = '细粉'
            }

            //下面都是屎山
            if(this.id == undefined){
                if(this.$route.query.type == '中药材'){
                    this.materialTypeStor = '中药材'
                } else if(this.$route.query.type == '辅料'){
                    this.materialTypeStor = '辅料'
                } else if(this.$route.query.type == '提取饮片'){
                    this.materialTypeStor = '提取饮片'
                } else if(this.$route.query.type == '配方颗粒'){
                    this.materialTypeStor = '配方颗粒'
                }else if(this.$route.query.type == '配方颗粒(浸膏粉)'){
                    this.materialTypeStor = '配方颗粒(浸膏粉)'
                }
                this.ruleForm.materialType = this.$route.query.type

                if (this.ruleForm.materialType == '配方颗粒') {
                        this.keliShow = true
                        this.wlShow = false
                        this.zypy = false
                        this.ruleForm.ypUnits = 'g'
                }else if(this.ruleForm.materialType == '中药饮片'){
                    this.zypy = true
                    this.keliShow = false
                    this.wlShow = false
                    this.ruleForm.ypUnits = '细粉'
                }
                else if(this.ruleForm.materialType == '中药饮片(半成品)'){
                    this.zypy = false
                    this.keliShow = false
                }else{
                        this.keliShow = false
                        this.wlShow = false
                        this.ruleForm.ypUnits = 'g'

                    }
                this.$store.commit('removeRuform','')
            }else{
                this.init()
            }


            if(this.$route.query.type == '辅料' || this.$route.query.type == '配方颗粒' ){
                this.ssssshow = false
            }else{
                this.ssssshow = true
            }
            // var ruleForm = this.$store.state.newStorge
            // if (ruleForm.materialType == '中药材') {
            //     this.ruleForm = this.$store.state.newStorge
            // } else if (ruleForm.inType == '辅料'){
            //     this.ruleForm = this.$store.state.newStorge
            // } else if (ruleForm.inType == '提取饮片'){
            //     this.ruleForm = this.$store.state.newStorge
            // } else if (ruleForm.inType == '配方颗粒'){
            //     this.ruleForm = this.$store.state.newStorge
            // } else{

            // }
            this.getunits()
        },
        methods: {

          changeStandard(){
            var str = ""
            var str1 = ""
            for(var i =0;i<this.standard.length;i++){
              str +=  this.standard[i].checkName +","
              str1 += this.standard[i].id + ','
            }
            var strlist = str.substring(0,str.lastIndexOf(","));

            var str1list = str1.substring(0,str1.lastIndexOf(","));
            this.ruleForm.checkName = strlist
            if(this.ruleForm.materialType == "提取饮片"){
              this.ruleForm.checkId = str1list
            }
            if(this.ruleForm.materialType == "配方颗粒" && this.ruleForm.ypCodeStandard == "2"){
              this.ruleForm.checkId2 = str1list
            }else{
              this.ruleForm.checkId = str1list
            }

          },
          getchecklist(e){
            // console.log(this.ruleForm.breedName)
            if(this.ruleForm.materialType == "提取饮片"){
              var data = "?type="+this.ruleForm.materialType  + "&standard=" + this.ruleForm.ypCodeStandard
              this.getcheckfindByname(data)
            }else if(this.ruleForm.materialType == "配方颗粒"){
              var data = "?type="+this.ruleForm.materialType  + "&standard=" + this.ruleForm.ypCodeStandard + "&breedName=" +this.ruleForm.breedName
              this.getcheckfindByname(data)
            }




          },
          getcheckfindByname(data){
            if(this.ruleForm.ypCodeStandard != "" && this.ruleForm.breedName !=""){
              // 检测依据
              check_findByName(data).then((res) =>{
                if(this.ruleForm.materialType == "配方颗粒" && this.ruleForm.ypCodeStandard == "2"){
                  this.checkList = res[0].checkNameDTOList

                }else{
                  this.checkList = res
                }
                this.standard = []
                // console.log(this.checkList)
              })
            }
          },


            added_unit(){
                this.technologies.push({specification:''})
            },
            deleteUnit(){
                 this.$confirm('是否确定删除该条地址?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        this.technologies.splice(index,1)
                        this.$notify({
                            title: '提示',
                            message: '删除成功',
                            type: 'success',
                            duration:1000
                        });
                    }).catch(() => {
                        this.$notify({
                            title: '提示',
                            message: '已取消删除',
                            type: 'info',
                            duration:1000
                        });
                    });
            },

            getunits(){
                unit_findByList("").then((res)=>{
                    this.units = res.data
                })
            },
            backPage () {
                this.$router.go(-1);
                // this.ruleForm = {}
                this.$store.commit('setStorName',this.ruleForm.materialType)
            },
            changeMtype(ele){
            this.ruleForm.ypCodeStandard = ""
            this.standard = ""
                if (ele == '配方颗粒') {
                    this.keliShow = true
                    this.wlShow = false
                    this.zypy = false
                    this.materialCode = ""
                    this.ruleForm.ypUnits = 'g'

                }else if(ele == '中药饮片'){
                    this.zypy = true
                    this.keliShow = false
                    this.wlShow = false
                    this.materialCode = ""
                    this.ruleForm.ypUnits = '细粉'
                }else if(ele == '中药饮片(半成品)'){
                    this.zypy = false
                    this.wlShow = true
                    this.keliShow = false
                }
                // else if(ele == '提取饮片'){
                //     this.wlShow = true
                //     this.keliShow = false
                // }
                else{
                    this.keliShow = false
                    this.wlShow = false
                }
            },
            unitLink(){
                this.$router.push({
                    path:'/unit'
                })
                this.$store.commit('setStorge',this.ruleForm)
            },
            // 提交预览
            submitRules(formName){
                this.$refs[formName].validate((valid) => {
                    console.log(valid);
                    if (valid) {
                      if(typeof this.ruleForm.checkId2 == "object" || typeof this.ruleForm.checkName == "object"){
                        var str = ""
                        var str1 = ""
                        for(var i =0;i<this.standard.length;i++){
                          str +=  this.standard[i].checkName +","
                          str1 += this.standard[i].id + ','
                        }
                        var strlist = str.substring(0,str.lastIndexOf(","));
                        var str1list = str1.substring(0,str1.lastIndexOf(","));
                        this.ruleForm.checkName = strlist
                        if(this.ruleForm.materialType == "提取饮片"){
                          this.ruleForm.checkId = str1list
                        }
                        if(this.ruleForm.materialType == "配方颗粒" && this.ruleForm.ypCodeStandard == "2"){
                          this.ruleForm.checkId2 = str1list
                        }else{
                          this.ruleForm.checkId = str1list
                        }
                      }


                        var arr = []
                        // technologies
                        for(var i=0;i<this.technologies.length;i++){
                            arr.push(this.technologies[i].specification)
                        }
                        // prodAddress
                        this.ruleForm.prodAddress = arr.join()
                         if(this.ruleForm.ypCodeStandard == 1){
                                this.ypCodeStandard = "国标"
                            }else if(this.ruleForm.ypCodeStandard == 2){
                                this.ypCodeStandard = "省标"
                            }

                        if (this.ruleForm.materialType == '配方颗粒') {
                            // if (this.ruleForm.loadingQuantity != '') {
                            //     if(this.ruleForm.loadingUnits == ''){
                            //         this.$notify.error({
                            //             title: '提示',
                            //             message: '装量单位必填！',
                            //             showClose: false,
                            //             duration:2000
                            //         });
                            //         return false;
                            //     }
                            // }
                            // if(this.ruleForm.inventoryCode != '') {

                                if (this.inventoryType == 'C50天津中药配方颗粒' || this.inventoryType == 'C50中药配方颗粒') {
                                    if (this.ruleForm.dispenserCode == '') {
                                        this.$notify.error({
                                            title: '提示',
                                            message: '发药机编码必填！',
                                            showClose: false,
                                            duration:2000
                                        });
                                        return false;
                                    }
                                }
								if(this.ruleForm.inventoryCode != '' && this.ruleForm.inventoryCode != this.inventoryCode){
									materialBreed_findInventoryCodeIsExist(this.ruleForm.inventoryCode).then((res)=>{
										if (res.data == false) {
											this.$notify.error({
												title: '提示',
												message: '存货代码重复，请重新输入！',
												showClose: false,
												duration:2000
											});
											this.ruleForm.inventoryCode = "";
											return false;
											this.showForm = false
										}else{
											this.showForm = true
										}
									})
								}
								if(this.ruleForm.inventoryCode == this.inventoryCode &&this.ruleForm.inventoryCode != ''){
									this.showForm = true
								}
                            // }
                            // if (this.ruleForm.ypQuantity != '') {
                            //     this.showForm = false
                            //     if(this.ruleForm.ypUnits == ''){
                            //         this.$notify.error({
                            //             title: '提示',
                            //             message: '装量对应饮片单位必填！',
                            //             showClose: false,
                            //             duration:2000
                            //         });
                            //         return false;
                            //     }
                            // }
                        // }
						}
                        //物料代码
                        console.log(this.ruleForm);

						if (this.ruleForm.materialCode) {
							materialBreed_isExist(`?code=${this.ruleForm.materialCode}&id=${this.id}`).then((res) =>{
								if (res.data == false) {
									this.$notify.error({
										title: '提示',
										message: '物料代码重复，请重新输入！',
										showClose: false,
										duration:2000
									});
									this.ruleForm.materialCode = "";
									return false;
									this.showForm = false
								}else{
									this.showForm = true
								}
							})
						}
                        this.showForm = true

                    } else{
                        return false;
                    }
                })
            },
            // 添加物料事件
            submitForm() {
                // if(this.id == undefined){
                    materialBreed_save(this.ruleForm).then((res)=>{
                        this.$notify({
                            title: '提示',
                            message: '保存成功',
                            type: 'success',
                            duration:1000
                        });
                        this.backPage()
                        this.$store.commit('setStorName',this.ruleForm.materialType)
                    })
                // }else{
                //     materialBreed_update(this.ruleForm).then((res)=>{
                //         this.$notify({
                //             title: '提示',
                //             message: '修改成功',
                //             type: 'success',
                //             duration:1000
                //         });
                //         this.backPage()
                //     })
                // }
            },
            //  编辑状态
            init(){

                // 回显表单
                materialBreed_findById(this.id).then((res) => {
                    this.ruleForm = res.data;
                  if(this.ruleForm.materialType == "中药饮片(半成品)" || this.ruleForm.materialType == "中药饮片"){
                      this.piecesStandardList.push(this.ruleForm.checkName)
                      this.piecesStandardName = this.ruleForm.checkName
                  }
                  if(this.ruleForm.materialType == "提取饮片"){
                    var data = "?type="+this.ruleForm.materialType  + "&standard=" + this.ruleForm.ypCodeStandard
                  }else if(this.ruleForm.materialType == "配方颗粒"){
                    var data = "?type="+this.ruleForm.materialType  + "&standard=" + this.ruleForm.ypCodeStandard + "&breedName=" +this.ruleForm.breedName
                  }

                  if (this.ruleForm.materialType == "配方颗粒" || this.ruleForm.materialType == "提取饮片"){
                    check_findByName(data).then((res) =>{
                      if(this.ruleForm.materialType == "配方颗粒" && this.ruleForm.ypCodeStandard == "2"){
                        this.checkList = res[0].checkNameDTOList
                        this.ruleForm.checkId = res[0].id
                      }else{
                        this.checkList = res
                      }
                    })
                  }

                  this.materialCode = this.ruleForm.materialCode
                  this.inventoryCode = this.ruleForm.inventoryCode

                  if(this.ruleForm.checkName){
                    this.ruleForm.checkName = this.ruleForm.checkName.split(",")
                  }




                  if(this.ruleForm.materialType == "配方颗粒" && this.ruleForm.ypCodeStandard == "2"){
                    if(this.ruleForm.checkId){
                      this.ruleForm.checkId2 = this.ruleForm.checkId2.split(",")
                    }
                  }else{
                    if(this.ruleForm.checkId){
                      this.ruleForm.checkId = this.ruleForm.checkId.split(",")
                    }
                  }

                  if(this.ruleForm.checkName){
                    for(var i=0;i<this.ruleForm.checkName.length;i++){
                      if(this.ruleForm.materialType == "配方颗粒" && this.ruleForm.ypCodeStandard == "2"){
                        console.log(1)
                        this.standard.push({
                          checkName:this.ruleForm.checkName[i],
                          id:this.ruleForm.checkId2[i]
                        })
                      }else{
                        // console.log(2)
                        this.standard.push({
                          checkName:this.ruleForm.checkName[i],
                          id:this.ruleForm.checkId[i]
                        })
                      }

                    }
                  }



                    if (res.data.materialType == '配方颗粒') {
                        this.keliShow = true
                        this.wlShow = false
                    }

                    // else if(res.data.materialType == '提取饮片'){
                    //     this.wlShow = true
                    //     this.keliShow = false
                    // }
                    else{
                        this.keliShow = false
                        this.wlShow = false
                    }
                    this.materialTypeStor = this.ruleForm.materialType
                     var arr = this.ruleForm.prodAddress.split(",")
                    // console.log(arr)
                    var arrList = []
                    for( var i= 0;i<arr.length;i++){
                        arrList.push({specification:arr[i]})
                    }
                    this.technologies = arrList
                })
            },
        }
    }
</script>
<style lang="less" scoped>
.styleWidth .el-input-group>.el-input__inner{ width: 200px !important;}
.styleWidth .el-select{ width: 60px !important;}
// .delete_btn{
//     margin-left:6px;
// }
</style>
